import { app, ipcMain, dialog } from 'electron'
import path from 'node:path'
import fs from 'node:fs'

const setupInstallerHandlers = () => {
    /**
     * 选择安装路径
     */
    ipcMain.handle('installer:select-path', async () => {
        const { filePaths } = await dialog.showOpenDialog({
          properties: ['openDirectory', 'createDirectory']
        })
        return filePaths[0] || app.getPath('appData')
    })

    ipcMain.on('installer:start', async (event, options) => {
        const { installPath } = options
        try {
            // 1. 创建安装目录
            await fs.promises.mkdir(installPath)
            // 2. 复制/解压应用文件
            const appPath = path.join(process.resourcesPath, 'app.zip')

        } catch (error) {
            
        }
    })

}

export {
    setupInstallerHandlers
}